package com.yhb.service.impl;

import com.yhb.channel.provider.ISessionVarProvider;
import me.edzh.spring.bootstrap.utils.Constants;
import org.apache.log4j.MDC;
import org.springframework.stereotype.Service;

@Service
public class SessionProviderImpl implements ISessionVarProvider {
    private final static String PREFIX = "channel-session-";
    @Override
    public void set(String key, Object val) {
        MDC.put(PREFIX + key, val);
    }

    @Override
    public Object get(String key) {
        if (KEY_CLIENT_IP.equals(key)) {
            return Constants.getCurrentRemoteIp();
        }
        return MDC.get(PREFIX + key);
    }
}
